# $Id$
# Maintainer: Gaetan Bisson <bisson@archlinux.org>
# Contributor: Allan McRae <allan@archlinux.org>
# Contributor: Simone Sclavi 'Ito' <darkhado@gmail.com>

pkgname=libjpeg-turbo
pkgver=1.5.2
pkgrel=1
pkgdesc='JPEG image codec with accelerated baseline compression and decompression'
url='http://libjpeg-turbo.virtualgl.org/'
arch=('i686' 'x86_64')
license=('custom')
makedepends=('nasm' 'jdk8-openjdk')
validpgpkeys=('7D6293CC6378786E1B5C496885C7044E033FDE16')
source=("http://downloads.sourceforge.net/project/${pkgname}/${pkgver}/${pkgname}-${pkgver}.tar.gz"{,.sig})
sha256sums=('9098943b270388727ae61de82adec73cf9f0dbb240b3bc8b172595ebf405b528'
            'SKIP')

provides=('libjpeg=8.1.2' 'turbojpeg')
conflicts=('libjpeg' 'turbojpeg')
replaces=('libjpeg' 'turbojpeg')

options=('!makeflags')

prepare() {
	cd "${srcdir}/${pkgname}-${pkgver}"
	sed 's/Szathmáry/Szathmary/g' -i java/org/libjpegturbo/turbojpeg/*.java
}

build() {
	cd "${srcdir}/${pkgname}-${pkgver}"
	export JNI_CFLAGS='-I/usr/lib/jvm/default/include -I/usr/lib/jvm/default/include/linux'
	./configure \
		--prefix=/usr \
		--mandir=/usr/share/man \
		--with-jpeg8 \
		--with-java \

	make
}

check() {
	cd "${srcdir}/${pkgname}-${pkgver}"
	make test
}

package() {
	cd "${srcdir}/${pkgname}-${pkgver}"
	make \
		DESTDIR="${pkgdir}" \
		docdir="/usr/share/doc/${pkgname}" \
		exampledir="/usr/share/doc/${pkgname}" \
		install
	
	install -m644 jpegint.h "${pkgdir}/usr/include" # required by other software

	install -d "${pkgdir}/usr/share/licenses/libjpeg-turbo"
	ln -s ../../doc/libjpeg-turbo/README.md "${pkgdir}"/usr/share/licenses/libjpeg-turbo
}
